package com.mucd.chat.test;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

public class ListTesting {

    @Test
    public void testList() {

        List<Long> list = new Vector<>();

        list.add(123L);
        list.add(321L);
        list.add(456L);


        //正解
//        Iterator<Long> iterator = list.iterator();
//        while (iterator.hasNext()) {
//            Long item = iterator.next();
//            if (item.equals(321L)) {
//                iterator.remove();
//            }
//        }

        //简写
        list.removeIf(item -> item.equals(321L));

//        错误实例
//        list.forEach(item->{
//            if (item.equals(321L)) {
//                list.remove(item);
//            }
//        });

        System.out.println("list = " + list);


    }

    @Test
    public void testNullIf() {
        SysUser sysUser = null;

        if (sysUser != null && sysUser.getUserId() > 0) {
            System.out.println("sysUser = " + sysUser);
        } else {
            System.out.println("sysUser = null");
        }

    }


}
